home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / Games / Glider 3.14 / source / Glider parts ƒ / I-GliderBody.p < prev   
Encoding:
Text File  |  1993-06-03  |  12.5 KB  |  323 lines  |  [TEXT/PJMM]

  1.  
  2.  
  3. program Glider313;        {Glider+ 3.14}
  4.  
  5. {Glider+ version 3.14, © 1989, 1990, 1991 March 13 by John Calhoun.    }
  6. {An "arcade-style" game for the Macintosh computer.        }
  7.  
  8.     uses
  9.         LogoWindo, AboutIt, Dialogs, Sound, GameUtilities, GliderMain, InitializeAll, HandleTheMenus;
  10.  
  11.     const
  12.         stackSize = 24000;
  13.         sleep = 1;
  14.         suspendResumeBit = $0001;
  15.         resuming = 1;
  16.         WNETrapNum = $60;
  17.         unimplTrapNum = $9F;
  18.  
  19.     var
  20.         theMenu, theItem, chCode, code, count: integer;
  21.         ch: char;
  22.         mResult, dummyLong, timeToLoop: longint;
  23.         myEvent: EventRecord;
  24.         whichWindow: WindowPtr;
  25.         tempRect: Rect;
  26.         theInput: TEHandle;
  27.         err: OSErr;
  28.         prefGet: Str255;
  29.         thisWorld: SysEnvRec;
  30.         leaving, eventHappened, hasWNE, inBackground, ignore: Boolean;
  31.  
  32. {==================================}
  33.  
  34.     procedure DoErrorSound (soundNumber: Integer);
  35.         var
  36.             dummyLong: LongInt;
  37.             tempVolume, i: Integer;
  38.     begin
  39.         GetSoundVol(tempVolume);
  40.         if (tempVolume <> 0) then
  41.             for i := 0 to soundNumber do
  42.                 begin
  43.                     FlashMenuBar(0);
  44.                     Delay(8, dummyLong);
  45.                     FlashMenuBar(0);
  46.                 end;
  47.     end;
  48.  
  49. {==================================}
  50.  
  51. {$I-}
  52. begin
  53.     SetApplLimit(Ptr(LongInt(GetApplLimit) - StackSize));
  54.     MaxApplZone;
  55.     for count := 1 to 12 do
  56.         MoreMasters;
  57.     InitGraf(@thePort);
  58.     InitFonts;
  59.     FlushEvents(everyEvent, 0);
  60.     InitWindows;
  61.     InitMenus;
  62.     TEInit;
  63.     InitDialogs(nil);
  64.  
  65.     ErrorSound(@DoErrorSound);
  66.  
  67.     for count := 1 to 3 do
  68.         ignore := EventAvail(EveryEvent, myEvent);
  69.     inBackground := FALSE;
  70.  
  71.     timeToLoop := TickCount;
  72.  
  73.     Init_LogoWindo;                                            {Set up Soft Dorothy Software Logo window    }
  74.     Open_LogoWindo;                                        {Display her (scanned from 1800's engraving)}
  75.     InitAllRooms;                                            {Set up object data in levelArray                }
  76.     ReadInScores(prefGet);                                {Call up hi scores and preferences from RSRC    }
  77.     InitAllVariables(prefGet);                                {Set up all those nasty global variables            }
  78.     Init_My_Menus;                                        {Bring up the menu bar                            }
  79.     err := SysEnvirons(1, thisWorld);                    {Check on the set up of the Mac game is on        }
  80.     with thisWorld do
  81.         begin
  82.             if (machineType <= 0) then                        {If less than a Mac Plus (=2) then quit now!    }
  83.                 ExitToShell
  84.             else
  85.                 begin
  86.                     if (systemVersion >= $0602) then
  87.                         begin                                            {Now, must be 6.02 or greater for the sound    }
  88.                             soundOn := TRUE;
  89.                             inhibitSound := FALSE;
  90.                             CheckItem(GetMenu(L_Options), C_Sound_On, soundOn);
  91.                         end
  92.                     else
  93.                         begin
  94.                             soundOn := FALSE;                            {Otherwise, turn it off, change the menu item,}
  95.                             inhibitSound := TRUE;
  96.                             SetItem(GetMenu(L_Options), C_Sound_On, 'No Sound : need ≥ Sys 6.02');
  97.                             DisableItem(GetMenu(L_Options), C_Sound_On);        {and disable it (changing the name is a public    }
  98.                         end;                                            {service mssg. to tell them WHY no sound).    }
  99.                 end;
  100.         end;
  101.     hasWNE := (NGetTrapAddress(WNETrapNum, ToolTrap) <> NGetTrapAddress(unimplTrapNum, toolTrap));
  102.  
  103.     theInput := nil;
  104.     leaving := FALSE;                {The following lines of code deal with the sexy}
  105.     count := 0;                        {logo for Soft Dorothy Software.  We have        }
  106.     repeat                            {already brought up the window, now we        }
  107.         count := count + 1;            {enter a loop that waits either for the count to}
  108.         Delay(10, dummyLong);        {reach 50 passes, or the player to cause an    }
  109.         if (count >= 50) then        {event.  I used the playMask because it was     }
  110.             leaving := TRUE;            {handy and already defined above.                }
  111.     until (EventAvail(everyEvent, myEvent) or (leaving));
  112.     Close_LogoWindo;                {Okay, now we close the window and move on.}
  113.     InitCursor;                        {Get us that arrow cursor                        }
  114.     Init_GliderMain;                {Get the main window ready for calling up        }
  115.     Open_GliderMain;                {Call it out of the RSRC fork and show it.        }
  116.     Init_AboutIt;                    {Go ahead and initialize the "About" window    }
  117.     GetDateTime(RandSeed);        {This neat simple line keeps the it random.        }
  118.     RedrawHiScores;                {Send in the banner gliders with the hiscores    }
  119.     highScoresOut := TRUE;        {Let the program know the scores are out.        }
  120.  
  121.     repeat                                {Start of main event loop                }
  122.         if (hasWNE) then
  123.             eventHappened := WaitNextEvent(everyEvent, myEvent, 0, nil)
  124.         else
  125.             begin
  126.                 SystemTask;
  127.                 eventHappened := GetNextEvent(everyEvent, myEvent);
  128.             end;
  129.  
  130.         if (eventHappened) then
  131.             begin
  132.                 code := FindWindow(myEvent.where, whichWindow);
  133.                 case myEvent.what of
  134.                     MouseDown: 
  135.                         case code of
  136.                             inMenuBar: 
  137.                                 begin
  138.                                     mResult := MenuSelect(myEvent.Where);    {Do menu selection                }
  139.                                     theMenu := HiWord(mResult);                    {Get the menu list number        }
  140.                                     theItem := LoWord(mResult);                    {Get the menu list item number    }
  141.                                     Handle_My_Menu(doneFlag, Pausing, Playing, gliderCraft, soundOn, leftControl, rightControl, theMenu, theItem, theInput);
  142.                                 end;
  143.                             inGoAway: 
  144.                                 begin
  145.                                     if TrackGoAway(whichWindow, myEvent.where) then
  146.                                         begin
  147.                                             Close_AboutIt;    {Close this window    }
  148.                                             EnableItem(GetMenu(L_Apple), 0);
  149.                                             EnableItem(GetMenu(L_Game), 0);
  150.                                             EnableItem(GetMenu(L_Options), 0);
  151.                                             DrawMenuBar;
  152.                                         end;
  153.                                 end;
  154.                             inContent: 
  155.                                 begin                                    {Handle hit inside a window    }
  156.                                     Do_AboutIt(myEvent, theInput);    {Call up dialog routine.        }
  157.                                 end;
  158.                             inSysWindow: 
  159.                                 SystemClick(myEvent, whichWindow);    {Let other programs in    }
  160.                             otherwise
  161.                                 begin
  162.                                 end;
  163.                         end;                {end - case code of        }
  164.                     KeyDown: 
  165.                         begin                                        {Get the key and handle it        }
  166.                             with myevent do                        {Check for menu command keys    }
  167.                                 begin
  168.                                     chCode := BitAnd(message, CharCodeMask);        {Get character    }
  169.                                     ch := CHR(chCode);                    {Change to ASCII                    }
  170.                                     if (Odd(modifiers div CmdKey)) then
  171.                                         begin
  172.                                             mResult := MenuKey(ch);        {See if menu selection            }
  173.                                             theMenu := HiWord(mResult);    {Get the menu list number        }
  174.                                             theItem := LoWord(mResult);    {Get the menu item number        }
  175.                                             if (theMenu <> 0) then        {See if a list was selected        }
  176.                                                 Handle_My_Menu(doneFlag, Pausing, Playing, gliderCraft, soundOn, leftControl, rightControl, theMenu, theItem, theInput); {Do the menu selection}
  177.                                         end;
  178.                                 end;                          {End for with}
  179.                         end;
  180.                     UpDateEvt: 
  181.                         begin
  182.                             whichWindow := WindowPtr(myEvent.message); {Get the window the update is for}
  183.                             BeginUpdate(whichWindow);        {Set the clipping to the update area    }
  184.                             CopyBits(virginMap, mainWindow^.portBits, screenArea, screenArea, srcCopy, mainWindow^.visRgn);
  185.                             Update_AboutIt(whichWindow);    {Update this window                    }
  186.                             EndUpdate(whichWindow);            {Return to normal clipping area        }
  187.                         end;
  188.                     ActivateEvt: 
  189.                         begin
  190.                             whichWindow := WindowPtr(myevent.message);    {Get the window to be activated            }
  191.                             if odd(myEvent.modifiers) then                        {Make sure it is Activate                }
  192.                                 SelectWindow(whichWindow);                        {Activate the window by selecting it    }
  193.                         end;
  194.                     App4Evt: 
  195.                         case BSR(myEvent.message, 24) of    {high byte of message}
  196.                             1:                          {suspendResumeMessage}
  197.                                 if (BitAnd(myEvent.message, suspendResumeBit) = resuming) then
  198.                                     inBackground := FALSE
  199.                                 else
  200.                                     begin
  201.                                         inBackground := TRUE;        {it was a suspend event}
  202.                                         if (chanPtr <> nil) then
  203.                                             err := SndDisposeChannel(chanPtr, TRUE);
  204.                                         chanPtr := nil;
  205.                                     end;
  206.                             otherwise
  207.                                 ;
  208.                         end; {CASE}
  209.                     otherwise
  210.                 end;                              {End of case            }
  211.             end;                                {end of GetNextEvent    }
  212.  
  213.         while ((Playing) and (not Pausing) and (not inBackground)) do
  214.             begin
  215.                 if (burning) or (crushed) then
  216.                     DoDyingDisplay        {Burning or crushed gliders fall and die...no player interaction!    }
  217.                 else
  218.                     begin
  219.                         if (hasWNE) then
  220.                             eventHappened := WaitNextEvent(everyEvent, myEvent, 0, nil)
  221.                         else
  222.                             begin
  223.                                 SystemTask;
  224.                                 eventHappened := GetNextEvent(everyEvent, myEvent);
  225.                             end;
  226.  
  227.                         if eventHappened then
  228.                             begin
  229.                                 code := FindWindow(myEvent.where, whichWindow);
  230.                                 case myEvent.what of
  231.                                     MouseDown: 
  232.                                         if code = inMenuBar then
  233.                                             begin
  234.                                                 mResult := MenuSelect(myEvent.Where);        {Do menu selection                }
  235.                                                 theMenu := HiWord(mResult);                    {Get the menu list number        }
  236.                                                 theItem := LoWord(mResult);                    {Get the menu list item number    }
  237.                                                 Handle_My_Menu(doneFlag, Pausing, Playing, gliderCraft, soundOn, leftControl, rightControl, theMenu, theItem, theInput);
  238.                                             end;
  239.                                     KeyDown: 
  240.                                         begin
  241.                                             ch := Chr(BitAnd(myEvent.message, CharCodeMask));        {Get character        }
  242.                                             if (Odd(myEvent.modifiers div CmdKey)) then
  243.                                                 begin
  244.                                                     mResult := MenuKey(ch);                        {See if menu selection            }
  245.                                                     theMenu := HiWord(mResult);                    {Get the menu list number        }
  246.                                                     theItem := LoWord(mResult);                    {Get the menu item number        }
  247.                                                     if (theMenu <> 0) then                        {See if a list was selected        }
  248.                                                         Handle_My_Menu(doneFlag, Pausing, Playing, gliderCraft, soundOn, leftControl, rightControl, theMenu, theItem, theInput); {Do the menu selection}
  249.                                                 end;
  250.                                             if ((ch = leftControl) and (not stalling)) then    {i.e. "If the player is pressing    }
  251.                                                 begin                                    {the key to go left or stall the plane."        }
  252.                                                     stalling := TRUE;                    {Then boolean variable 'stalling' to TRUE    }
  253.                                                     if (gliderCraft) then                {The MacII CopyMask routine scales and    }
  254.                                                         ResizeARect(playerDropRect, 1);        {thus "drop" rect needs resizing    }
  255.                                                 end;                                    {Otherwise, it garbages up the graphic.    }
  256.                                             if ((ch = rightControl) and (stalling)) then            {Likewise for right...            }
  257.                                                 begin                                    {Note:  There is no change in the graphic    }
  258.                                                     stalling := FALSE;                    {when you are in dart mode.  Only the        }
  259.                                                     if (gliderCraft) then                {glider tips back graphically.  So, no need    }
  260.                                                         ResizeARect(playerDropRect, 0);        {to resize the dart rect.                }
  261.                                                 end;
  262.                                         end;
  263.                                     otherwise
  264.                                         begin
  265.                                         end;
  266.                                 end;            {end of case                        }
  267.                             end;                {end of GetNextEvent                }
  268.                     end;                    {end of if not burning or crushed}
  269.                 ComputeGliderPos;    {This routine checks for objects (vents, cnadles etc...).    }
  270.                 ComputeStatus;        {Here we check to see if the glider is still on the screen.    }
  271.                 if (playing) then        {It could be the player has died during this pass, in that    }
  272.                     begin                {case, we want to skip over these routines.                }
  273.                         if (not crushed) then    {We offset the glider according to the results of    }
  274.                             begin            {ComputeGliderPos and ComputeStatus.                    }
  275.                                 OffsetRect(playerDropRect, moveHori, moveVert);    {moveHori and    }
  276.                                 OffsetRect(shadowDropRect, moveHori, 0);    {moveVert were modified}
  277.                                 OffsetRect(vitalArea, moveHori, moveVert);    {in the aforementioned    }
  278.                             end;                {routines.  Note:  the shadow is not offset vertically.        }
  279.                         if (candleThere) then    {If we have a candle in the room...                    }
  280.                             HandleCandle;        {This routine will handle the flicker of the flame.        }
  281.                         DrawGlider;        {Here we draw the glider according to it's new posit.        }
  282.                         oldPlayerRect := playerDropRect;    {Set the old rects equal to the present    }
  283.                         oldShadowRect := shadowDropRect;    {rects for the UnionRect routine.    }
  284.                         if (levelOn > 13) then    {The last two rooms deserve special treatment.    }
  285.                             begin                {Room 14 has only 1 copter because it has the dripping}
  286.                                 if (levelOn = 14) then    {ceiling to deal with (keep it fast).                }
  287.                                     begin
  288.                                         DoDrip;        {Deal with the dripping water in room 14.                }
  289.                                         DoCopter;        {Do the paper helicopter routine.                        }
  290.                                     end
  291.                                 else
  292.                                     DoCat;            {Note: No DoCopter for room 15.  The cat is enough!    }
  293.                             end
  294.                         else
  295.                             begin
  296.                                 DoCopter;            {The other rooms (1..13) simply have copters.        }
  297.                             end;
  298.                         gameTime := gameTime + 1;    {# of loops through this repeat loop per room        }
  299.                         totalTime := totalTime + 1;        {# for the whole game ( demo mode needs this)    }
  300.                         ObscureCursor;
  301.                         repeat
  302.                         until TickCount >= timeToLoop;
  303.                         timeToLoop := TickCount + gameSpeed;
  304.                     end;                        {end - if still playing (we may have died during this pass)    }
  305.             end;                            {end - while Playing do                                            }
  306.     until doneFlag;                    {end of the event loop                                            }
  307.  
  308.     if (chanPtr <> nil) then
  309.         err := SndDisposeChannel(chanPtr, true);
  310.  
  311.     ClosePort(objectsPort);
  312.     DisposPtr(Ptr(objectsPort));
  313.     ClosePort(loadPort);
  314.     DisposPtr(Ptr(loadPort));
  315.     ClosePort(virginPort);
  316.     DisposPtr(Ptr(virginPort));
  317.  
  318.     Close_GliderMain;                {When you've quit the program, close the main window.        }
  319.  
  320.     if (scoresChanged) then
  321.         WriteOutScores;
  322.  
  323. end.                                    {End of the program}